<?php 
//ini_set('display_errors','On');
header("Content-Type: text/html;charset=utf-8");
include("../function/_nosql.php"); //
include("../function/function.php");
include("../_include.user.judge.php");
//读取订单信息
$WIDout_trade_no = $_GET['WIDout_trade_no'];
$aid = $_GET['aid'];
$uid = $_SESSION['kboy_userid'];
$time = date("Y");
$order_num = getClassName("kboy_order","order_num","order_no='".$WIDout_trade_no."'");
$moneys = getClassName("kboy_forum_active","active_all_money","id=$aid");
$money = ($moneys*$order_num);
$subject = getClassName("kboy_forum_active","active_title","id=$aid");
$active_tian = getClassName("kboy_forum_active","active_tian","id=".$aid);
$rUnique = $WIDout_trade_no;//订单号
$order_no = substr($rUnique,0,4);
if($order_no == "0500"){
	$money = '500';
	$subject = "金额充值500";
}else if($order_no == "0501"){
	$money = '1000';
	$subject = "金额充值1000";
}else if($order_no == "0502"){
	$money = '3000';
	$subject = "金额充值3000";
}else{
	if(strstr($WIDout_trade_no,'_')){//申请成为cva
	     mysql_query("update  kboy_user  set user_trade_no='".$WIDout_trade_no."' where uid= '".$_SESSION['kboy_userid']."' ");

		 $money = 50;

		 $subject ='申请成为CVA';
	}else{
		//表单提交
		if(getClassName("kboy_user","user_style","uid=$uid") == 1){
			if(getClassName("kboy_jiangli","hdnian","uid=$uid and hd_jieshu=0") == $time and getClassName("kboy_jiangli","hd_yhui","uid=$uid and hd_jieshu=0") == 1){
			$leiji = getClassName("kboy_jiangli","hd_leiji","uid=$uid and hd_jieshu=0");
			$renshu = getClassName("kboy_jiangli","hdrenshu","uid=$uid and hd_jieshu=0");
				if($order_num == 1){
					if($active_tian < 3 and $renshu > 30){
					$money = ($money*0.90);
					$jl_shuom = "带入新会员".$renshu."人，优惠10%";
					}else if($active_tian < 3 and $leiji > 10 and $leiji < 31){
						$money = ($money*0.95);
						$jl_shuom = "累计参加".$leiji."次，优惠5%";
					}else if($active_tian < 3 and $leiji > 30){
						$money = ($money*0.90);
						$jl_shuom = "累计参加".$leiji."次，优惠10%";
					}
				}else if($order_num == 2 or $order_num == 3){
					if($active_tian < 3 and $renshu > 30){
						$benren = ($moneys*0.90);
						$money = ($order_num-1)*$moneys+$benren;
						$jl_shuom = "带入新会员".$renshu."人，和".($order_num-1)."位朋友，优惠10%";
					}else if($active_tian < 3 and $leiji > 10 and $leiji < 31){
						$benren = ($moneys*0.95);
						$money = ($order_num-1)*$moneys+$benren;
						$jl_shuom = "累计参加".$leiji."次，和".($order_num-1)."位朋友，优惠5%";
					}else if($active_tian < 3 and $leiji > 30){
						$benren = ($moneys*0.9);
						$money = ($order_num-1)*$moneys+$benren;
						$jl_shuom = "累计参加".$leiji."次，和".($order_num-1)."位朋友，优惠10%";
					}
				}else if($active_tian < 3 and $order_num-1 < 6 and  $order_num-1 > 2){
					$benren = ($moneys*0.70);
					$money = ($order_num-1)*$moneys+$benren;
						$jl_shuom = "参加本次活动，带新人".($order_num-1)."位，优惠30%";
				}else if($active_tian < 3 and $order_num-1 > 5){
					$benren = ($moneys*0.50);
					$money = ($order_num-1)*$moneys+$benren;
						$jl_shuom = "参加本次活动，带新人".($order_num-1)."位，优惠50%";
				}
				if(isset($jl_shuom)){
					$jl_danhao= getClassName('kboy_jljilu','jl_danhao',"uid='$uid' and aid = '$aid'");
							if($jl_danhao){
								mysql_query("update kboy_jljilu jl_danhao='$WIDout_trade_no' where uid='$uid' and aid = '$aid'");
							}else{
								$mysql = new sqlstr("kboy_jljilu");
								$mysql -> set("uid",$uid);
								$mysql -> set("aid",$aid);
								$mysql -> set("jl_shuom",$jl_shuom);
								$mysql -> set("jl_danhao",$rUnique);
								$mysql -> set("jl_jine",$money);
								$mysql -> set("jl_time",date("Y-m-d H:i:s", time()));
								$news_sql = $mysql -> insertSql();
								$news_res = mysql_query($news_sql);
							}
				}else{
					$benren = getClassName("kboy_forum_active","active_cva_money","id=$aid");
					$money = ($order_num-1)*$moneys+$benren;
				}
					
			}else{
				$benren = getClassName("kboy_forum_active","active_cva_money","id=$aid");
				$money = ($order_num-1)*$moneys+$benren;
			}
		}
	}
}

?>

<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/> 
    <title>中国徒步网-支付中心</title>
</head>
<body  >
    <br/>
	  <div class="ok_order">
		<ul>
			  <dl style="margin:0 auto; text-align:center;">
	         <h1 style=" font-size:20px; color:#000; margin:10px 0px"><?php echo $subject; ?></h1>
             <h1 style=" font-size:18px; margin-bottom:20px; width:300px;">
			 <span style="color:#000">订单号:<p><strong style=" color:#c90800"><?php echo $rUnique;?></strong></p></span>
			 &nbsp;<span style="color:#000">金额为：<strong style=" color:#c90800"><?php echo $money;?>元</strong></span>
            </h1>
             </dl>
           </ul> 
        </div>
	<div align="center">
		<form action="yu_e_add.php?zhi=fu" method="post">
			<input type="hidden" name="oeder" id="oeder" value="<?php echo $rUnique;?>" />
			<input type="hidden" name="subject" id="" value="<?php echo $subject;?>" />
			<input type="hidden" name="money" id="" value="<?php echo $money;?>" />
			<input style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:20px;" type="submit" value="余额支付"/>
		</form>
	    <a href="../weipay/jsapi.php?WIDout_trade_no=<?php echo $rUnique;?>&aid=<?php echo $aid;?>" style="display:block;width:210px; height:50px;line-height:50px ; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:20px;text-decoration:none;">微信支付</a>
	</div>
</body>
</html>